package com.huizhonglm.diap.presenters.user;

import com.alibaba.fastjson.JSON;
import com.bruce.common.utils.EmptyUtil;
import com.huizhonglm.diap.api.API;
import com.huizhonglm.diap.api.HttpCallback;
import com.huizhonglm.diap.api.model.user.MyWalletParams;
import com.huizhonglm.diap.api.model.user.MyWalletResponse;
import com.huizhonglm.diap.core.utils.UserUtil;
import com.huizhonglm.diap.ui.user.iView.MyWalletIView;

/**
 * @author LiXiaoLong
 * @version 1.0
 * @since 2014-11-19 11:25
 */
public class MyWalletPresenter {

    private MyWalletIView mView;

    public MyWalletPresenter(MyWalletIView view) {
        mView = view;
    }

    public void loadData() {
        MyWalletParams params = new MyWalletParams();
        params.userId = UserUtil.getUserId();
        API.http().post("myWallet", params, new HttpCallback() {
            @Override
            public void onSuccess(String result) {
                if (!EmptyUtil.isEmpty(result)) {
                    MyWalletResponse resp = JSON.parseObject(result, MyWalletResponse.class);
                    if (resp != null) {
                        mView.onLoadDataSuccess(resp);
                    } else {
                        mView.onLoadDataFailure();
                    }
                } else {
                    mView.onLoadDataFailure();
                }
            }

            @Override
            public void onFailure(Throwable ex) {
                mView.onLoadDataFailure();
            }
        });
    }
}
